<?php

namespace Wechat\Controller;

class WorkflowController extends CommonController {

    public function index() {
        if(!check_access($this->customer["customer_id"], "0")){
            $this->error("您没有访问权限！");
            exit();
        }
        $type = $_REQUEST["type"];
        $this->assign("type", $type);
        $this->display("index");
    }
    public function addWorkorder() {
        $type = $_REQUEST["type"];
        if($type == 1){
            $name = "XWK-AFO-";
        }
        if($type == 2){
            $name = "XWK-SPN-";
        }
        if($type == 3){
            $name = "XWK-CP-";
        }
        $workorderId = D('Workorder')->add(array(
            'workorder_no' => $name.date('ymd',time()) . rand(0, 999),
            'workorder_type' => $type,
            'status' => -1,
            'version' => 2,
            'create_time' => getCurrentDate(),
            'creator_id'=> $this->customer["customer_id"],
        ));

        $this->redirect(U("workorder/index", array("id"=>$workorderId)));
    }

//    private function check_access()
//    {
//        $employee = D("Employee")->queryById($this->customer["customer_id"]);
//        //如果用户角色是1，则无需判断
//        $job = explode(',',$employee["job"]);
//        if($job["0"] == 1){
//            return true;
//        }else{
//            return false;
//        }
//    }
}